<?php

namespace app\admin\controller\home;

use app\common\controller\Backend;
use think\Cache;
use think\Db;
use think\Exception;
use think\Validate;
use think\Env;

/**
 *路印介绍配置
 *
 * @icon   fa fa-cogs
 * @remark 可以在此增改系统的变量和分组,也可以自定义分组和变量,如果需要删除请从数据库中删除
 */
class Set extends Backend
{

    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];
    /**
     * @var \app\common\model\Config
     */
    protected $model = null;
    private $redis;

    public function _initialize()
    {
        parent::_initialize();
        $this->redis = redis(Env::get('redis.host'), Env::get('redis.port'), Env::get('redis.pwd'), Env::get('redis.db'));
    }

    /**
     * 查看
     */
    public function index()
    {

        $image = $this->redis->hGet('humeng:set','image');
        $msg = $this->redis->hGet('humeng:set','msg');
        $phone = $this->redis->hGet('humeng:set','phone');
        $address = $this->redis->hGet('humeng:set','address');
        $longitude = $this->redis->hGet('humeng:set','longitude');
        $latitude = $this->redis->hGet('humeng:set','latitude');
        $contents = $this->redis->hGet('humeng:set','contents');
        $vip_content = $this->redis->hGet('humeng:set','vip_content');
        $images = $this->redis->hGet('humeng:set','images');
        $imagess = $this->redis->hGet('humeng:set','imagess');
        $imagebj = $this->redis->hGet('humeng:set','imagebj');

        $row = [
            'image' => $image,
            'msg' => $msg,
            'phone' => $phone,
            'address' => $address,
            'longitude' => $longitude,
            'latitude' => $latitude,
            'contents' => $contents,
            'vip_content' => $vip_content,
            'images' => $images,
            'imagess' => $imagess,
            'imagebj' => $imagebj,
        ];

        $this->view->assign('row', $row);
        return $this->view->fetch();
    }

    /**
     * 编辑a1
     * @param null $ids
     */
    public function edit($ids = null)
    {
        if ($this->request->isPost()) {
            //$this->token();
            $row = $this->request->post("row/a", [], 'trim');

            if ($row) {

                $this->redis->hSet('humeng:set','image',$row['image']);
                $this->redis->hSet('humeng:set','msg',$row['msg']);
                $this->redis->hSet('humeng:set','phone',$row['phone']);
                $this->redis->hSet('humeng:set','address',$row['address']);
                $this->redis->hSet('humeng:set','longitude',$row['longitude']);
                $this->redis->hSet('humeng:set','latitude',$row['latitude']);

                $this->success();
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
    }

    /**
     * 编辑a2
     * @param null $ids
     */
    public function edits($ids = null)
    {
        if ($this->request->isPost()) {
            //$this->token();
            $row = $this->request->post("row/a", [], 'trim');

            if ($row) {

                $this->redis->hSet('humeng:set','contents',$row['contents']);

                $this->success();
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
    }

    /**
     * 编辑a3
     * @param null $ids
     */
    public function editss($ids = null)
    {
        if ($this->request->isPost()) {
            //$this->token();
            $row = $this->request->post("row/a", [], 'trim');

            if ($row) {

                $this->redis->hSet('humeng:set','vip_content',$row['vip_content']);

                $this->success();
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
    }

    /**
     * 编辑a4
     * @param null $ids
     */
    public function editsss($ids = null)
    {
        if ($this->request->isPost()) {
            //$this->token();
            $row = $this->request->post("row/a", [], 'trim');

            if ($row) {

                $this->redis->hSet('humeng:set','images',$row['images']);
                $this->redis->hSet('humeng:set','imagebj',$row['imagebj']);

                $this->success();
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
    }

    /**
     * 编辑a5
     * @param null $ids
     */
    public function editssss($ids = null)
    {
        if ($this->request->isPost()) {
            //$this->token();
            $row = $this->request->post("row/a", [], 'trim');

            if ($row) {

                $this->redis->hSet('humeng:set','imagess',$row['imagess']);

                $this->success();
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
    }
}
